import java.sql.*;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbcp.BasicDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class DruidPool {
    private static Properties properties = new Properties();
    private static DataSource ds;
    static {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("druid.properties");
        try {
            properties.load(is);
            ds = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static Connection   getCon() throws Exception {
        return  ds.getConnection();
    }
    public static void close(ResultSet rs, Statement statement,PreparedStatement ps, Connection con)throws Exception{
            if(rs!=null){
             rs.close();
            }
            if(ps!=null){
                ps.close();
            }
            if(con!=null){
                con.close();
            }
            if(statement!=null){
                statement.close();
            }
    }
}

